package hihocode;

import java.util.Scanner;

public class Offer17Problem3 {

	public static final int MAX = 100002;
	int[] array = new int[MAX];
	long count = 0;

	// 数组中的所有逆序对
	public static void main(String[] args) {
		Offer17Problem3 object = new Offer17Problem3();
		object.getRes();
	}

	public void getRes() {
		Scanner scanner = new Scanner(System.in);
		while (scanner.hasNext()) {
			int n = scanner.nextInt();
			count = 0;
			for (int i = 0; i < n; i++) {
				array[i] = scanner.nextInt();
			}
			System.out.println(mergeSort(array, 0, n - 1));
		}
		scanner.close();
	}

	public long mergeSort(int[] array, int low, int high) {
		if (low < high) {
			int middle = (low + high) / 2;
			mergeSort(array, low, middle);
			mergeSort(array, middle + 1, high);
			merge(array, low, middle, high);
		}
		return count;
	}

	public void merge(int[] input, int left, int center, int right) {
		int[] tempArray = new int[right - left + 1];
		int mid = center + 1;
		int temp = left;
		int current = 0;
		while (left <= center && mid <= right) {
			if (input[left] > input[mid]) {
				tempArray[current++] = input[mid++];
				/*
				 * 如果input[left]>input[mid]，那么表明下标为left~center的值都会比input[mid]大;
				 * (5,7,8)(4,9)合并为 3+0+0+0
				 */
				count += center - left + 1;
			} else {
				tempArray[current++] = input[left++];
			}
		}
		// 只会执行一个
		while (left <= center) {
			tempArray[current++] = input[left++];
		}
		while (mid <= right) {
			tempArray[current++] = input[mid++];
		}
		current = 0;
		while (temp <= right) {
			input[temp++] = tempArray[current++];
		}
	}
}
